package com.zjj.edu.system.service.impl;

import com.zjj.edu.common.constant.UserConstants;
import com.zjj.edu.common.utils.DateUtils;
import com.zjj.edu.common.utils.StringUtils;
import com.zjj.edu.system.domain.SysSemester;
import com.zjj.edu.system.mapper.SysSemesterMapper;
import com.zjj.edu.system.service.ISysSemesterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 学期Service业务层处理
 *
 * @author zjj
 * @date 2020-06-02
 */
@Service
public class SysSemesterServiceImpl implements ISysSemesterService
{
    @Autowired
    private SysSemesterMapper sysSemesterMapper;

    /**
     * 查询学期
     *
     * @param id 学期ID
     * @return 学期
     */
    @Override
    public SysSemester selectSysSemesterById(Long id)
    {
        return sysSemesterMapper.selectSysSemesterById(id);
    }

    /**
     * 查询学期列表
     *
     * @param sysSemester 学期
     * @return 学期
     */
    @Override
    public List<SysSemester> selectSysSemesterList(SysSemester sysSemester)
    {
        return sysSemesterMapper.selectSysSemesterList(sysSemester);
    }

    /**
     * 新增学期
     *
     * @param sysSemester 学期
     * @return 结果
     */
    @Override
    public int insertSysSemester(SysSemester sysSemester)
    {
        sysSemester.setCreateTime(DateUtils.getNowDate());
        return sysSemesterMapper.insertSysSemester(sysSemester);
    }

    /**
     * 修改学期
     *
     * @param sysSemester 学期
     * @return 结果
     */
    @Override
    public int updateSysSemester(SysSemester sysSemester)
    {
        sysSemester.setUpdateTime(DateUtils.getNowDate());
        return sysSemesterMapper.updateSysSemester(sysSemester);
    }

    /**
     * 删除学期对象
     *
     * @return 结果
     */
    @Override
    public int deleteSysSemesterByIds(SysSemester sysSemester)
    {
        return sysSemesterMapper.deleteSysSemesterByIds(sysSemester);
    }

    @Override
    public String checkNameUnique(SysSemester vo) {
        Long id = StringUtils.isNull(vo.getId()) ? -1L : vo.getId();
        SysSemester info = sysSemesterMapper.checkNameUnique(vo.getName(), vo.getTenantId());
        if (StringUtils.isNotNull(info) && info.getId().longValue() != id.longValue())
        {
            return UserConstants.NAME_NOT_UNIQUE;
        }
        return UserConstants.NAME_UNIQUE;
    }

    @Override
    public List<SysSemester> selectAllSysSemesterList(long tenantId) {
        return sysSemesterMapper.selectAllSysSemesterList(tenantId);
    }
}
